//
// Created by Eugeny Grishul
//
// See license at http://bamelg.com/license.txt
//

using System;
using System.Runtime.InteropServices;

namespace Platform.Zlib {
	[ExternLibrary( Image = "/usr/lib64/libz.so.1" )]
	public static partial struct ZlibApi {
		public const SbcsString Version = "1.2.11";

		public extern static uintptr adler32( uintptr adler, byte* buf, uint len );
		public extern static uintptr adler32_combine( uintptr p0, uintptr p1, intptr p2 );
		public extern static uintptr adler32_combine64( uintptr p0, uintptr p1, long p2 );
		public extern static uintptr adler32_z( uintptr adler, byte* buf, uintptr len );
		public extern static ZlibError compress( byte* dest, uintptr* destLen, byte* source, uintptr sourceLen );
		public extern static ZlibError compress2( byte* dest, uintptr* destLen, byte* source, uintptr sourceLen, int level );
		public extern static uintptr compressBound( uintptr sourceLen );
		public extern static uintptr crc32( uintptr crc, byte* buf, uint len );
		public extern static uintptr crc32_combine( uintptr p0, uintptr p1, intptr p2 );
		public extern static uintptr crc32_combine64( uintptr p0, uintptr p1, long p2 );
		public extern static uintptr crc32_z( uintptr adler, byte* buf, uintptr len );
		public extern static ZlibError deflate( z_stream* strm, FlushOptions flush );
		public extern static uintptr deflateBound( z_stream* strm, uintptr sourceLen );
		public extern static ZlibError deflateCopy( z_stream* dest, z_stream* source );
		public extern static ZlibError deflateEnd( z_stream* strm );
		public extern static int deflateGetDictionary( z_stream* strm, byte* dictionary, uint* dictLength );
		public extern static ZlibError deflateInit_( z_stream* strm, int level, CUtf8String version, int streamSize );
		public extern static ZlibError deflateInit2_( z_stream* strm, int level, CompressionMethod method, int windowBits, int memLevel, DeflateStrategy strategy, CUtf8String version, int streamSize );
		public extern static ZlibError deflateParams( z_stream* strm, int level, DeflateStrategy strategy );
		public extern static ZlibError deflatePending( z_stream* strm, uint* pending, int* bits );
		public extern static ZlibError deflatePrime( z_stream* strm, int bits, int value );
		public extern static ZlibError deflateReset( z_stream* strm );
		public extern static ZlibError deflateResetKeep( z_stream* p0 );
		public extern static ZlibError deflateSetDictionary( z_stream* strm, byte* dictionary, uint dictLength );
		public extern static ZlibError deflateSetHeader( z_stream* strm, gz_header* head );
		public extern static int deflateTune( z_stream* strm, int goodLength, int maxLazy, int niceLength, int maxChain );
		public extern static uint* get_crc_table();
		public extern static int gzbuffer( gzFile* file, uint size );
		public extern static void gzclearerr( gzFile* file );
		public extern static int gzclose( gzFile* file );
		public extern static int gzclose_r( gzFile* file );
		public extern static int gzclose_w( gzFile* file );
		public extern static int gzdirect( gzFile* file );
		public extern static gzFile* gzdopen( int fd, sbyte* mode );
		public extern static int gzeof( gzFile* file );
		public extern static sbyte* gzerror( gzFile* file, int* errnum );
		public extern static int gzflush( gzFile* file, int flush );
		public extern static uintptr gzfread( void* buf, uintptr size, uintptr nitems, gzFile* file );
		public extern static uintptr gzfwrite( void* buf, uintptr size, uintptr nitems, gzFile* file );
		public extern static int gzgetc( gzFile* file );
		public extern static int gzgetc_( gzFile* file );
		public extern static sbyte* gzgets( gzFile* file, sbyte* buf, int len );
		public extern static intptr gzoffset( gzFile* p0 );
		public extern static long gzoffset64( gzFile* p0 );
		public extern static gzFile* gzopen( sbyte* p0, sbyte* p1 );
		public extern static gzFile* gzopen64( sbyte* p0, sbyte* p1 );
		public extern static int gzputc( gzFile* file, int c );
		public extern static int gzputs( gzFile* file, sbyte* s );
		public extern static int gzread( gzFile* file, void* buf, uint len );
		public extern static int gzrewind( gzFile* file );
		public extern static intptr gzseek( gzFile* p0, intptr p1, int p2 );
		public extern static long gzseek64( gzFile* p0, long p1, int p2 );
		public extern static int gzsetparams( gzFile* file, int level, int strategy );
		public extern static intptr gztell( gzFile* p0 );
		public extern static long gztell64( gzFile* p0 );
		public extern static int gzungetc( int c, gzFile* file );
		public extern static int gzvprintf( gzFile* file, sbyte* format, void* va );
		public extern static int gzwrite( gzFile* file, void* buf, uint len );
		public extern static ZlibError inflate( z_stream* strm, FlushOptions flush );
		public extern static ZlibError inflateBack( z_stream* strm, Functors.Func<void*, byte**, uint> in, void* inDesc, Functors.Func<void*, byte*, uint, int> out, void* outDesc );
		public extern static ZlibError inflateBackEnd( z_stream* strm );
		public extern static ZlibError inflateBackInit_( z_stream* strm, int windowBits, byte* window, CUtf8String version, int streamSize );
		public extern static uintptr inflateCodesUsed( z_stream* p0 );
		public extern static ZlibError inflateCopy( z_stream* dest, z_stream* source );
		public extern static ZlibError inflateEnd( z_stream* strm );
		public extern static int inflateGetDictionary( z_stream* strm, byte* dictionary, uint* dictLength );
		public extern static ZlibError inflateGetHeader( z_stream* strm, gz_header* head );
		public extern static ZlibError inflateInit_( z_stream* strm, CUtf8String version, int streamSize );
		public extern static ZlibError inflateInit2_( z_stream* strm, int windowBits, CUtf8String version, int streamSize );
		public extern static intptr inflateMark( z_stream* strm );
		public extern static ZlibError inflatePrime( z_stream* strm, int bits, int value );
		public extern static ZlibError inflateReset( z_stream* strm );
		public extern static ZlibError inflateReset2( z_stream* strm, int windowBits );
		public extern static ZlibError inflateResetKeep( z_stream* p0 );
		public extern static ZlibError inflateSetDictionary( z_stream* strm, byte* dictionary, uint dictLength );
		public extern static ZlibError inflateSync( z_stream* strm );
		public extern static ZlibError inflateSyncPoint( z_stream* p0 );
		public extern static ZlibError inflateUndermine( z_stream* p0, int p1 );
		public extern static int inflateValidate( z_stream* p0, int p1 );
		public extern static ZlibError uncompress( byte* dest, uintptr* destLen, byte* source, uintptr sourceLen );
		public extern static int uncompress2( byte* dest, uintptr* destLen, byte* source, uintptr* sourceLen );
		public extern static CString zError( int p0 );
		public extern static uintptr zlibCompileFlags();
		public extern static CString zlibVersion();
	}
	public enum CompressionMethod : uint {
		Z_DEFLATED = 8,
	}
	public enum DeflateStrategy : uint {
		Z_DEFAULT_STRATEGY = 0,
		Z_FILTERED =         1,
		Z_HUFFMAN_ONLY =     2,
		Z_RLE =              3,
		Z_FIXED =            4,
	}
	[Flags]
	public enum FlushOptions : uint {
		Z_NO_FLUSH =   0,
		Z_SYNC_FLUSH = 2,
		Z_FINISH =     4,
		Z_FULL_FLUSH = 3,
	}
	public enum ZlibError : int {
		Z_VERSION_ERROR = -6,
		Z_BUF_ERROR =     -5,
		Z_MEM_ERROR =     -4,
		Z_DATA_ERROR =    -3,
		Z_STREAM_ERROR =  -2,
		Z_ERRNO =         -1,
		[ErrorCodeSuccess]
		Z_OK =             0,
		Z_STREAM_END =     1,
		Z_NEED_DICT =      2,
	}
	[ExplicitSize( Size = 80 )]
	[Alignment( Boundary = 8 )]
	public partial struct gz_header {
		[ExplicitOffset( Offset = 0 )]
		public int text;
		[ExplicitOffset( Offset = 8 )]
		public uintptr time;
		[ExplicitOffset( Offset = 16 )]
		public int xflags;
		[ExplicitOffset( Offset = 20 )]
		public int os;
		[ExplicitOffset( Offset = 24 )]
		public byte* extra;
		[ExplicitOffset( Offset = 32 )]
		public uint extra_len;
		[ExplicitOffset( Offset = 36 )]
		public uint extra_max;
		[ExplicitOffset( Offset = 40 )]
		public CUtf8String name;
		[ExplicitOffset( Offset = 48 )]
		public uint name_max;
		[ExplicitOffset( Offset = 56 )]
		public CUtf8String comment;
		[ExplicitOffset( Offset = 64 )]
		public uint comm_max;
		[ExplicitOffset( Offset = 68 )]
		public int hcrc;
		[ExplicitOffset( Offset = 72 )]
		public int done;
	}
	[ExplicitSize( Size = 24 )]
	[Alignment( Boundary = 8 )]
	public partial struct gzFile {
		[ExplicitOffset( Offset = 0 )]
		public uint have;
		[ExplicitOffset( Offset = 8 )]
		public byte* next;
		[ExplicitOffset( Offset = 16 )]
		public intptr pos;
	}
	public partial struct internal_state {
	}
	[ExplicitSize( Size = 112 )]
	[Alignment( Boundary = 8 )]
	public partial struct z_stream {
		[ExplicitOffset( Offset = 0 )]
		public byte* next_in;
		[ExplicitOffset( Offset = 8 )]
		public uint avail_in;
		[ExplicitOffset( Offset = 16 )]
		public uintptr total_in;
		[ExplicitOffset( Offset = 24 )]
		public byte* next_out;
		[ExplicitOffset( Offset = 32 )]
		public uint avail_out;
		[ExplicitOffset( Offset = 40 )]
		public uintptr total_out;
		[ExplicitOffset( Offset = 48 )]
		public sbyte* msg;
		[ExplicitOffset( Offset = 56 )]
		public internal_state* state;
		[ExplicitOffset( Offset = 64 )]
		public Functors.Func<void*, uint, uint, void*> zalloc;
		[ExplicitOffset( Offset = 72 )]
		public Functors.Action<void*, void*> zfree;
		[ExplicitOffset( Offset = 80 )]
		public void* opaque;
		[ExplicitOffset( Offset = 88 )]
		public int data_type;
		[ExplicitOffset( Offset = 96 )]
		public uintptr adler;
		[ExplicitOffset( Offset = 104 )]
		public uintptr reserved;
	}
}